package com.example.shop.mapper;


import com.example.shop.model.OrderForm;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

@Repository
public interface OrderMapper extends Mapper<OrderForm> {
    /**
     * select c.name, c.price, o.created, o.remark, s.stateName
     * from orderFrom o
     * left join commodity c
     * on o.cId = c.Id
     * left join state s
     * on o.stateId = s.id
     * where o.uId = 2
     */
//    @Select("select c.name, c.price, o.created, o.remark, o.id, s.stateName from orderFrom o left join commodity c on o.cId = c.id left join state s on o.stateId = s.id where o.uId = #{uId}")
//    @Results({
//            @Result(property = "id", column = "id"), //加此行，否则id值为空
//            @Result(property = "orderFrom", column = "id", many = @Many(select = "com.hh.springboot.mapper.OrderMapper.selectOne")),
//            @Result(property = "commodity", column = "id", many = @Many(select = "com.hh.springboot.mapper.CommodityMapper.selectOne"))
//    })
//    @Insert("INSERT INTO orderFrom (id, uId, created, orders, sumPrice, stateId, remark) " +
//            "VALUES (null, #{uId}, #{created}, #{orders}, #{sumPrice}, #{stateId}, #{remark})")
    int insertOrder(OrderForm orderForm);

    int getCount(int uId);

    List<OrderForm> getPageBean(int uId, int pageNo, int pageSize);

    int deleteById(Integer id);

    int getDataCount();

    List<OrderForm> getOrdersForms(@Param("startNum") int startNum, @Param("pageSize") int pageSize, @Param("search") String search);
}
